package com.codeduck.validate.controller;

import com.codeduck.validate.entity.User;
import com.codeduck.validate.groups.Groups;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 分组校验,校验的对象为 {@link com.codeduck.validate.entity.User}
 *   insert 方法并不关心 ID 字段
 *   update 方法需要去验证 ID 是否为空
 *
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2021-12-26
 */
@RestController
public class GroupValidateController {

    @GetMapping("/insert")
    public String insert(@Validated(value = Groups.Default.class) User user) {
        return "insert";
    }


    @GetMapping("/update")
    public String update(@Validated(value = Groups.Update.class) User user) {
        return "update";
    }
}
